#include "Ast.h"
#include <format>


namespace Pomian
{
	BinNode::BinNode(AstNode* left, AstNode* right)
		: m_left(left)
		, m_right(right)
	{
	}
	BinNode::~BinNode()
	{
		if (m_left != nullptr) 
		{
			delete m_left;
			m_left = nullptr;
		}

		if (m_right != nullptr)
		{
			delete m_right;
			m_right = nullptr;
		}
	}
	NumberNode::NumberNode(NumberToken *token)
		: m_token(token)
	{
	}
	NumberNode::~NumberNode()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	BinaryExpr::BinaryExpr(OperatorToken* token, AstNode* left, AstNode* right)
		: BinNode(left, right)
		, m_token(token)
	{
	}
	BinaryExpr::~BinaryExpr()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	IdentifierNode::IdentifierNode(IdentifierToken* token)
		: m_token(token)
	{
	}
	IdentifierNode::~IdentifierNode()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	KeywordNode::KeywordNode(KeywordToken* token)
		: m_token(token)
	{
	}
	KeywordNode::~KeywordNode()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	OperatorNode::OperatorNode(OperatorToken* token)
		: m_token(token)
	{
	}
	OperatorNode::~OperatorNode()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	SeperatorNode::SeperatorNode(SeperatorToken* token)
		: m_token(token)
	{
	}
	SeperatorNode::~SeperatorNode()
	{
		if (m_token != nullptr)
		{
			delete m_token;
			m_token = nullptr;
		}
	}
	IfStmnt::IfStmnt(AstNode* condition, AstNode* thenBlock, AstNode* elseBlock)
		: m_condition(condition)
		, m_thenBlock(thenBlock)
		, m_elseBlock(elseBlock)
	{

	}
	IfStmnt::~IfStmnt() 
	{
		if (m_condition != nullptr)
		{
			delete m_condition;
		}
		if (m_thenBlock != nullptr)
		{
			delete m_thenBlock;
		}
		if (m_elseBlock != nullptr)
		{
			delete m_elseBlock;
		}
	}

	WhileStmnt::WhileStmnt(AstNode* condition, AstNode* body)
		: m_condition(condition)
		, m_body(body)
	{

	}
	WhileStmnt::~WhileStmnt()
	{
		if (m_condition != nullptr)
		{
			delete m_condition;
		}
		if (m_body != nullptr)
		{
			delete m_body;
		}
	}

	NullStmnt* NullStmnt::Null = new NullStmnt();

	FlagNode::FlagNode(FlagToken* token) 
		: m_token(token)
	{

	}

	ListNode::~ListNode() 
	{
		for (AstNode* child : m_children)
		{
			delete child;
		}
		m_children.clear();
	}

}

